jun.NotaDebetDetilWin = Ext.extend(Ext.Window, {
    title: 'Nota Debet Detil',
    modez: 1,
    width: 365,
    height: 145,
    layout: 'form',
    modal: true,
    padding: 5,
    closeForm: false,
    initComponent: function () {
        this.items = [
            {
                xtype: 'form',
                frame: false,
                bodyStyle: 'background-color: #E4E4E4; padding: 10px',
                id: 'form-NotaDebetDetil',
                labelWidth: 100,
                labelAlign: 'left',
                layout: 'form',
                ref: 'formz',
                border: false,
                items: [
                    {
                        xtype: 'combo',
                        fieldLabel: 'Konsumen',
                        typeAhead: true,
                        triggerAction: 'all',
                        lazyRender: true,
                        mode: 'local',
                        minChars: 3,
                        store: jun.rztKonsumen,
                        matchFieldWidth: !1,
                        itemSelector: "div.search-item",
                        tpl: new Ext.XTemplate('<tpl for="."><div class="search-item">',
                            '<span style="float:left;width:120;font-weight: bold">{konsumen_code}</span>' +
                            '<span style="font-weight: bold">{konsumen_name}</span>', "</div></tpl>"),
                        listWidth: 350,
                        hiddenName: 'konsumen_id',
                        valueField: 'konsumen_id',
                        forceSelection: true,
                        hideTrigger: true,
                        displayField: 'konsumen_name',
                        ref: '../konsumen',
                        allowBlank: false,
                        anchor: '100%'
                    },
                    {
                        xtype: 'numericfield',
                        fieldLabel: 'Total',
                        hideLabel: false,
                        //hidden:true,
                        name: 'amount',
                        id: 'amountid',
                        ref: '../amount',
                        maxLength: 30,
                        value: 0,
                        anchor: '100%'
                    }
                ]
            }
        ];
        this.fbar = {
            xtype: 'toolbar',
            items: [
                {
                    xtype: 'button',
                    text: 'Simpan',
                    hidden: false,
                    ref: '../btnSave'
                },
                {
                    xtype: 'button',
                    text: 'Simpan & Tutup',
                    ref: '../btnSaveClose'
                },
                {
                    xtype: 'button',
                    text: 'Batal',
                    ref: '../btnCancel'
                }
            ]
        };
        jun.NotaDebetDetilWin.superclass.initComponent.call(this);
//        this.on('activate', this.onActivate, this);
        this.btnSaveClose.on('click', this.onbtnSaveCloseClick, this);
        this.btnSave.on('click', this.onbtnSaveclick, this);
        this.btnCancel.on('click', this.onbtnCancelclick, this);
        if (this.modez == 1 || this.modez == 2) {
            this.btnSave.setVisible(false);
            this.btnSaveClose.setVisible(false);
        } else {
            this.btnSave.setVisible(true);
            this.btnSaveClose.setVisible(true);
        }
    },
    btnDisabled: function (status) {
        this.btnSave.setDisabled(status);
        this.btnSaveClose.setDisabled(status);
    },
    saveForm: function () {
        this.btnDisabled(true);
        var amount = parseFloat(this.amount.getValue());
        var konsumen_id = this.konsumen.getValue();
        var a = jun.rztNotaDebetDetil.findExact("konsumen_id", konsumen_id);
        if (a > -1) {
            Ext.MessageBox.alert("Error", "Konsumen sudah dimansukkan.");
            this.btnDisabled(false);
            return;
        }
        var c = jun.rztNotaDebetDetil.recordType,
            d = new c({
                konsumen_id: konsumen_id,
                amount: amount
            });
        jun.rztNotaDebetDetil.add(d);
        if (this.modez == 0) {
            Ext.getCmp('form-NotaDebetDetil').getForm().reset();
            this.btnDisabled(false);
        }
        if (this.closeForm) {
            this.close();
        }
    },
    onbtnSaveCloseClick: function () {
        this.closeForm = true;
        this.saveForm(true);
    },
    onbtnSaveclick: function () {
        this.closeForm = false;
        this.saveForm(false);
    },
    onbtnCancelclick: function () {
        this.close();
    }

});